package com.jdd.enterprise.domain.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jdd.enterprise.domain.entity.MenuDO;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
 * @Brief
 * @Author chenyl
 * @Date 2024-02-28
 * @Version 1.0.0
 */
public interface MenuMapper extends BaseMapper<MenuDO> {
    /**
     * 根据菜单编码查询菜单及所有子级数据
     * 需要确保菜单编码对应的数据存在库中
     *
     * @param menuCode 菜单编码
     * @return 菜单列表
     */
    @Select("WITH RECURSIVE sub_data AS (SELECT * FROM menu WHERE menu_code = #{menuCode} UNION ALL SELECT M.* FROM menu AS M INNER JOIN sub_data sd ON M.parent_code = sd.menu_code ) SELECT * FROM sub_data WHERE deleted = 1 ORDER BY parent_code,sort;")
    List<MenuDO> listAllByMenuCode(String menuCode);
    /**
     * 根据菜单编码查询所有子级数据
     * 不会查询出菜单编码对应的数据
     *
     * @param menuCode 菜单编码
     * @return 菜单列表
     */
    @Select("WITH RECURSIVE sub_data AS (SELECT * FROM menu WHERE parent_code = #{menuCode} UNION ALL SELECT M.* FROM menu AS M INNER JOIN sub_data sd ON M.parent_code = sd.menu_code ) SELECT * FROM sub_data WHERE deleted = 1 ORDER BY parent_code,sort;")
    List<MenuDO> listAllByParentCode(String menuCode);
}
